#ifndef __CAPTURE_H__
#define __CAPTURE_H__

#include "camera.h"

#define _CHECK_PIX_FMT_YUYV(val, fmt) (val == V4L2_PIX_FMT_YUYV ? V4L2_PIX_FMT_YUYV : fmt)

#define _CHECK_PIX_FMT_MJPEG(val, fmt) (val == V4L2_PIX_FMT_MJPEG ? V4L2_PIX_FMT_MJPEG : _CHECK_PIX_FMT_YUYV(val, fmt))

#define SET_PIXEL_FORMAT(fmt, val) (fmt == V4L2_PIX_FMT_MJPEG ? V4L2_PIX_FMT_MJPEG : _CHECK_PIX_FMT_MJPEG(val, fmt))

void V4l2SearchFormat(int fd, unsigned int *fmt);
int V4L2SetBufType(int fd, unsigned int *bufType);
int V4L2GetFmt(int fd, struct DeviceFormat *deviceFormat);
int V4L2SetFmt(int fd, struct DeviceFormat *deviceFormat);
int V4L2ReqBuffers(int fd, int count, struct DeviceFormat *deviceFormat);
int V4L2MmapBuffer(int fd, int index, struct DeviceFormat *deviceFormat);
int V4L2QueueBuffer(int fd, int index, struct DeviceFormat *deviceFormat);
int V4L2DequeueBuffer(int fd, int *index, struct DeviceFormat *deviceFormat);
int V4L2StreamOn(int fd, enum v4l2_buf_type type);
int V4L2StreamOff(int fd, enum v4l2_buf_type type);
void V4L2FreeBuf(struct DeviceFormat *deviceFormat);

int Capture(const char *dev_name, struct DeviceFormat *deviceFormat, CallBack cb);

#endif /* end of __CAPTURE_H__ */
